angular.module('starter.controllers')
  .service('Api', function($q, http, Session, $timeout, $ionicLoading) {
    var resendSecond = 10,
      secondLeft = resendSecond,
      isGettingCode = false;
    return {
      login: function(uid, pwd) {
        return http.load('login', {
          userName: uid,
          passWord: pwd
        }, {
          loadingMsg: '登录中'
        });
      },
      checkBeforePost: function(checkFun) {
        var deferred = $q.defer();
        $timeout(function() {
          var errMsg = checkFun.call(this);
          if (errMsg) {
            $ionicLoading.show({
              template: errMsg,
              duration: 1000
            });
            deferred.reject();
          } else {
            deferred.resolve();
          }
        });
        return deferred.promise;
      }
    };
  });
